package servlets;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.StringConstants;

import database.DatabaseOperations;

public class AdminViewJobs extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private DatabaseOperations databaseOperations;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		databaseOperations = new DatabaseOperations();
		try {
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			String title = "Database Result";
			String docType = "<!doctype html public \"-//w3c//dtd html 4.0 "
					+ "transitional//en\">\n";
			out.println(docType + "<html>\n" + "<head><title>" + title
					+ "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n"
					+ "<h1 align=\"center\">" + title + "</h1>\n");
			// Set response content type
			for(String s: databaseOperations.getAllJobs()){
				out.println(s);
				out.println("<br>");
				out.println("<br>");
			}
			
			out.println("<a href='"+StringConstants.admin_homepage+"'> Go to home page </a>");
			out.println("</body></html>");
			
	//		response.setContentType("application/json");
	//	    response.setCharacterEncoding("UTF-8");
	//	    response.getWriter().write(databaseOperations.getJob(3).toString()); 
		} finally {
			databaseOperations.closeConnection();
		}
	}
	

}
